//***********************************************************************
//	File:		Flame.cpp
//	Author:		
//	Course:		SGP 1405
//	Purpose:	
//***********************************************************************
//***********************************************************************
//	Purposfully left blank for all comments regarding this file 
//	
//	
//	
//***********************************************************************



#include "Flame.h"
#include "../ParticleSystem/Emitter.h"
#include "../GameObjects/Enemy.h"
#include "../Message/DestroyEntityMessage.h"

#include "../SGD Wrappers/SGD_GraphicsManager.h"

#include "../GameStates/Play.h"

#include <random>


Flame::Flame(float posX, float posY, Entity* owner)
{
	float addedRotation = rand() % 393; // PI / 8 
	addedRotation /= 1000.0f; 

	if (rand() % 2 == 1)
	{
		addedRotation = -addedRotation; 
	}

	SetDamage(5); 
	//SetFinalSound();
	//SetFlameEffect();
	SetHasCollided(false); 
	//SetImage();
	SetOwnerType(owner);
	SetPosition(SGD::Point{ posX, posY }); 
	SetRange(150);
	SetRotation(owner->GetRotation() + addedRotation);
	SetSize(SGD::Size{ 4, 4 }); 
	SetSpeed(150);
	SetVelocity(SGD::Vector{ 0, -1 }); 
	originalPos = owner->GetPosition(); 
}

void Flame::Update(float dt)
{
	SGD::Vector flameRange = GetPosition() - originalPos; 

	SGD::Vector newVelocity = { 0, -1 };
	newVelocity.Rotate(GetRotation());
	newVelocity = newVelocity * GetSpeed();

	SetVelocity(newVelocity);

	if (flameRange.ComputeLength() >= m_fRange)
	{
		DestroyEntityMessage* pEntityToDestroy = new DestroyEntityMessage(this);
		pEntityToDestroy->QueueMessage();
	}
	//Update the Emitter

	//Final line of function
	Entity::Update(dt);
}

void Flame::Render()
{
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance(); 

	SGD::Rectangle myRect = GetRect(); 

	SGD::Point camera = Play::GetInstance()->GetCameraPos();

	SGD::Point playerPos = GetPosition();
	myRect.left -= camera.x;
	myRect.right -= camera.x;
	myRect.top -= camera.y;
	myRect.bottom -= camera.y; 

	pGraphics->DrawRectangle(myRect, { 255, 0, 0 }); 
	//Render the Emitter

}

void Flame::HandleCollision(const IEntity* pOther)
{
	switch (pOther->GetType())
	{
	case ENT_ANKLEBITER:
	{

	}
	case ENT_BASHER:
	{

	}
	case ENT_DISRUPTOR:
	{

	}
	case ENT_MECHATROOPER:
	{

	}
	case ENT_MOTHERBRAIN:
	{

	}
	case ENT_PWNER:
	{

	}
	case ENT_SPIDERMINE:
	{

	}
	case ENT_STRIKER:
	{

	}
	case ENT_TANKOSAURUS:
	{
		DestroyEntityMessage* pEntityToDestroy = new DestroyEntityMessage(this); 
		pEntityToDestroy->QueueMessage(); 
	}
	}
	
}

void Flame::HandleEvent()
{

}

SGD::Rectangle Flame::GetRect() const
{
	return SGD::Rectangle
	{
	GetPosition() - GetSize() / 2,
	GetPosition() + GetSize() / 2
	};
}


